package com.vidmt.api.modules.sys.utils;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class VerStatUtil {
	public static class LastLoginItem {
		public String os;
		public Integer ver;
		public Long uid;
		public Date time;
		public String channel;
	}

	private static final Map<String, LastLoginItem> lastLoginMap = new HashMap<>();
	private static final Map<String, Integer> osCntMap = new HashMap<>();

	public static void put(Long uid, String os, Integer ver, String channel) {
		int ioscnt = osCntMap.getOrDefault(os, 0);
		osCntMap.put(os, ioscnt + 1);

		LastLoginItem item = new LastLoginItem();
		item.os = os;
		item.ver = ver;
		item.uid = uid;
		item.time = new Date();
		item.channel = channel;
		lastLoginMap.put(os + "-" + ver + "-" + channel, item);
	}

	public static void remove(String resource) {
		String[] arr = resource.split("-");
		if (arr.length > 2) {
			String os = arr[1];
			int ioscnt = osCntMap.getOrDefault(os, 0);
			osCntMap.put(os, ioscnt - 1);
		}
	}

	public static Map<String, LastLoginItem> getLastLoginMap() {
		return lastLoginMap;
	}

	public static Map<String, Integer> getOsCntMap() {
		return osCntMap;
	}

}
